export default {
  state: { // state
    myAnswers: '',
    correctNumThis: '',
    startAnswer: false,
    initRankList: 0
  },
  getters: {
    myAnswers: state => state.myAnswers,
    correctNumThis: state => state.correctNumThis,
    startAnswer: state => state.startAnswer,
    initRankList: state => state.initRankList
  },
  mutations: {
    SAVE_ANSWERS (state, data) {
      state.correctNumThis = 0
      state.myAnswers = data
      data.map((item) => {
        if (item.myAnswer === item.correctAnswer) {
          state.correctNumThis++
        }
      })
    },
    CHANGE_QUESTIONNUM (state, data) {
      state.correctNumThis = data
    },
    CHANGE_STARTANSWER (state, data) {
      state.startAnswer = data
    },
    CHANGE_INITRANKLIST (state, data) {
      state.initRankList = data
    }
  },
  actions: {
    saveAnswers ({dispatch, commit}, data) {
      commit('SAVE_ANSWERS', data)
    },
    changeQuestionNum ({dispatch, commit}, data) {
      commit('CHANGE_QUESTIONNUM', data)
    },
    changeStartAnswer ({dispatch, commit}, data) {
      commit('CHANGE_STARTANSWER', data)
    },
    changeinitRankList ({dispatch, commit}, data) {
      commit('CHANGE_INITRANKLIST', data)
    }
  }
}
